from typing import Dict, Any
import time
from 组件.rabbitmq import RabbitMQTickPublisher

class MQStockOrderSaver:

    def __init__(self):
        self.saver = RabbitMQTickPublisher()

    def save_order(self,order_data: Dict[str, Any]) -> bool:
        self.saver.publish_order(order_data=order_data)
        return True

order_saver_mq = MQStockOrderSaver()

# 使用示例
if __name__ == "__main__":
    # 创建保存器（每5条或每秒自动刷新）
    saver = MQStockOrderSaver()

    # 模拟实时交易信号数据（格式要与启动交易系统一致）
    orders = [
        {
            "type": "buy", 
            "code": "513050.SH",
            "order_remark":"金叉买入"
        },
        {
            "type": "sell", 
            "code": "513060.SH",
            "order_remark":"平仓"
        },
        {
            "type": "close", 
            "code": "513120.SH",
            "order_remark":"无"
        }
    ]

    print("开始发送交易信号...")
    # 逐个保存
    for order in orders:
        saver.save_order(order)
        time.sleep(1)  # 每秒发送一个信号
    
    print("交易信号发送完成！")